package com.study.springCustom.spring.io;

import java.io.InputStream;

// 封装了资源路径信息，对外提供
public class ClasspathResource implements Resource {

    private String resource;

    public ClasspathResource(String resource) {
        this.resource = resource;
    }

    @Override
    public InputStream getInputStream() {
        if (resource.startsWith("classpath:")){
            resource = resource.substring(10);
        }
        if (resource.startsWith("classpath*:")){
            resource = resource.substring(11);
        }
        return this.getClass().getClassLoader().getResourceAsStream(resource);
    }

}
